from django.db import models

# Create your models here.

# 定义数据模型 一个数据模型对应一个数据表
class User(models.Model):
    genderchoices = [('男','M'),('女','F')]
    name = models.CharField(max_length=16,unique=True,null=False)
    password = models.CharField(max_length=16)
    gender = models.CharField(max_length=16,choices=genderchoices)
    age = models.IntegerField()


# 6.23日考
class Project(models.Model):
    user_id=models.IntegerField()
    project_name=models.CharField(max_length=64,unique=True)
    start_time=models.DateField()
    end_time=models.DateField()
    status=models.CharField(max_length=64)
    create_time=models.DateField(auto_now_add=True)


class Author(models.Model):
    name=models.CharField(max_length=16,unique=True,null=False)
    gender=models.CharField(max_length=8)
    age=models.IntegerField()
    address=models.CharField(max_length=32)

class Book(models.Model):
    categorychoies=[("历史","历史"),("心理学","心理学"),("武侠","武侠"),("文学","文学")]
    name=models.CharField(max_length=16,unique=True,null=False)
    price=models.DecimalField(max_digits=8,decimal_places=2) # DecimalField 写小数，(123456.78)max_digits是最大位数的意思，第二个decimal_places是小数
    category=models.CharField(max_length=16,choices=categorychoies)
    pubishdata=models.DateTimeField(null=False)
    pubisher=models.CharField(max_length=16,default='清华出版社')
    author=models.ForeignKey(Author,on_delete=models.CASCADE,related_name="book")
    creaetime=models.DateTimeField(auto_now_add=True)
    updatetime=models.DateTimeField(auto_now=True)

class Address(models.Model):
    addressdetail=models.CharField(max_length=64,unique=True)
    city=models.CharField(max_length=64)
    province=models.CharField(max_length=64)
    zip=models.IntegerField(default=100100)

class Mstore(models.Model):
    name=models.CharField(max_length=64,unique=True)
    manager=models.CharField(max_length=64)
    startdate=models.DateField()
    address = models.OneToOneField(Address,on_delete=models.CASCADE,related_name='mstore')

class TestCase(models.Model):
    name=models.CharField(max_length=64,primary_key=True)
    step=models.TextField()
    expect=models.CharField(max_length=128)
    acutal=models.CharField(max_length=128,null=True)
    writeperson=models.CharField(max_length=64)

# 6.26周考更新
class ItemTrade(models.Model):
    item_id=models.CharField(max_length=64,unique=True,verbose_name='标识物品')
    title=models.CharField(max_length=64,verbose_name='物品标题')
    price=models.FloatField(verbose_name='物品价格')
    seller_name=models.CharField(max_length=64,verbose_name='卖家姓名')
    is_available=models.BooleanField(verbose_name='物品是否可售')

# VUE
class acount(models.Model):
    name=models.CharField(max_length=64,unique=True)
    password=models.CharField(max_length=64)


# 学生
class Student(models.Model):
    name=models.CharField(max_length=64)
    age=models.IntegerField()

# 多对多
# 班级
class Course(models.Model):
    name=models.CharField(max_length=64)
    time=models.IntegerField()
    stuents=models.ManyToManyField(Student,related_name='course')

